package com.tanhua.server.controller;

import com.tanhua.model.dto.RecommendUserDto;
import com.tanhua.model.vo.NearUserVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.TodayBest;
import com.tanhua.server.service.TanhuaService;
import org.bouncycastle.cert.ocsp.RespData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tanhua")
public class TanhuaController {

    @Autowired
    private TanhuaService tanhuaService;

    @GetMapping("/todayBest")
    public ResponseEntity todayBest() {
        TodayBest vo = tanhuaService.todayBest();
        return ResponseEntity.ok(vo);
    }

    /**
     * 查询分页推荐好友列表
     */
    @GetMapping("/recommendation")
    public ResponseEntity recommendation(RecommendUserDto dto) {
        PageResult pr = tanhuaService.recommendation(dto);
        return ResponseEntity.ok(pr);
    }

    /**
     * 查看佳人信息
     */
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable("id") Long id) {
        TodayBest best = tanhuaService.personalInfo(id);
        return ResponseEntity.ok(best);
    }

    /**
     * 查看陌生人问题
     */
    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(Long userId) {
        String question = tanhuaService.strangerQuestions(userId);
        return ResponseEntity.ok(question);
    }

    /**
     * 回复陌生人问题
     */
    @PostMapping("/strangerQuestions")
    public ResponseEntity replyQuestions2(@RequestBody Map map) {
        //前端传递的id是Integer，本地数据库使用long类型，需要转换
        Long userId = Long.valueOf(map.get("userId").toString()); //这个userId是指被回复的陌生人的ID
        String reply = map.get("reply").toString();
        tanhuaService.replyQuestion(userId, reply);
        return ResponseEntity.ok(null);
    }

    /**
     * 探花-推荐用户列表
     */
    @GetMapping("/cards")
    public ResponseEntity cards() {
        List<TodayBest> todayBests = tanhuaService.cards();
        return ResponseEntity.ok(todayBests);
    }
    /**
     * 探花-喜欢
     */
    @GetMapping("/{id}/love")
    public ResponseEntity love(@PathVariable("id")Long userId){
        tanhuaService.love(userId);
        return ResponseEntity.ok(null);
    }

    /**
     * 探花-不喜欢
     */
    @GetMapping("/{id}/unlove")
    public ResponseEntity unlove(@PathVariable("id")Long userId){
        tanhuaService.unlove(userId);
        return ResponseEntity.ok(null);
    }
    /**
     * 探花-搜附近
     */
    @GetMapping("/search")
    public ResponseEntity search(String gender,@RequestParam(defaultValue = "2000") String distance){
        List<NearUserVo> list = tanhuaService.findNearUser(gender,distance);
        return ResponseEntity.ok(list);
    }
}
